/**
 * 收获登记管理初始化
 */
var ReceiveBasicInformation = {
    id: "ReceiveBasicInformationTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ReceiveBasicInformation.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '合同号', field: 'receive_contract_number', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '合同状态', field: 'receiveIsfinish', visible: true, align: 'center', valign: 'middle'},
            {title: '起运日期', field: 'receive_start_date', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '到货日期', field: 'receive_arrival_date', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '制单员', field: 'receive_trade_person', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '审核员', field: 'receiveCheck', visible: true, align: 'center', valign: 'middle'},
            {title: '发货人', field: 'receiveConsigner', visible: true, align: 'center', valign: 'middle'},
            {title: '发货人电话', field: 'receiveConsignerTell', visible: true, align: 'center', valign: 'middle'},
            {title: '发货人地址', field: 'receiveConsignerPlace', visible: true, align: 'center', valign: 'middle'},
            {title: '收货人', field: 'receiveConsignee', visible: true, align: 'center', valign: 'middle'},
            {title: '收货人电话', field: 'receiveConsigneeTell', visible: true, align: 'center', valign: 'middle'},
            {title: '收货人地址', field: 'receiveConsigneePlace', visible: true, align: 'center', valign: 'middle'},
            {title: '付款方式', field: 'receivePaymentMethod', visible: true, align: 'center', valign: 'middle'},
            {title: '总运费', field: 'receive_gross_freight', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '总信息费', field: 'receive_gross_messagefee', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '总提货费', field: 'receive_gross_pickup_charge', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '是否代收货款', field: 'receiveIscollectMoney', visible: true, align: 'center', valign: 'middle'},
            {title: '送货方式', field: 'receiveShippingMethod', visible: true, align: 'center', valign: 'middle'},
            {title: '是否听通知发货', field: 'receiveIsinformDeliver', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'receiveRemark', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
ReceiveBasicInformation.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ReceiveBasicInformation.seItem = selected[0];
        return true;
    }
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
ReceiveBasicInformation.formParams = function() {
    var queryData = {};
    queryData['consigner'] = $("#consigner").val();
    queryData['consignee'] = $("#consignee").val();
    queryData['type'] = $("#type").val();
    queryData['receiveContractNumber'] = $("#receiveContractNumber").val();
    queryData['consignerMobile'] = $("#consignerMobile").val();
    queryData['consigneeMobile'] = $("#consigneeMobile").val();
    queryData['consignerPlace'] = $("#consignerPlace").val();
    queryData['consigneePlace'] = $("#consigneePlace").val();
    queryData['tradePerson'] = $("#tradePerson").val();
    queryData['startDate'] = $("#startDate").val();
    queryData['arrivalDate'] = $("#arrivalDate").val();

    return queryData;
}



/**
 * 打开查看收获登记详情
 */
ReceiveBasicInformation.openReceiveBasicInformationDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '收获登记详情',
            area: ['800px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/receiveBasicInformation/receiveBasicInformation_updatequery/' + ReceiveBasicInformation.seItem.id
        });
        this.layerIndex = index;
        layer.full(index);
    }
};


/**
 * 查询收获登记列表
 */
ReceiveBasicInformation.search = function () {
	ReceiveBasicInformation.table.refresh({query: ReceiveBasicInformation.formParams()});
};

$(function () {
    var defaultColunms = ReceiveBasicInformation.initColumn();
    var table = new BSTable(ReceiveBasicInformation.id, "/receiveBasicInformation/listbossquery", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(ReceiveBasicInformation.formParams());
    ReceiveBasicInformation.table = table.init();
});
